<?php
namespace app\run\model;

use think\Model;
use think\Db;
class Product extends Model{
	public static function index(){
		$res = Db::name('product')->select();
		return $res;
	}

	public static function selects(){
		$res = Db::name('product')->where('goods_state',1)->field('id,name')->select();
		return $res;
	}

	public static function insert(array $data){
		$res = Db::name('product')->insert($data);
		if(!$res) return 0;
		$id = Db::name('product')->getLastInsID();
		return $id;
	}

	public static function cat($options){
		$res = Db::name('product')->order('id desc')->paginate(5,false,$options);
		return $res;
	}

	public static function ajaxCat(){
			$res = Db::name('product')->where('goods_show',1)->field('id')->select();
			return $res;
		}

	public static function ajaxShow($goodsid,$goods_show){
			$data['goods_show'] = $goods_show;
			$res = Db::name('product')->where(array('id'=>array('eq',$goodsid)))->update($data);
	 	// $res;die;
	 	return $res;
		}


	 public static function state($goodsid,$stock){
	 	$data['stock'] = $stock;
	 	// return $state;
	 	$res = Db::name('product')->where(array('id'=>array('eq',$goodsid)))->update($data);
	 	// $res;die;
	 	return $res;
	 }


	 public static function ajaxDel($goodsid){
		$data['goods_state'] = 1;
		//$arr['car_state'] = 1;
		$res = Db::name('product')->where(array('id'=>array('eq',$goodsid)))->update($data);
		//if($res){
			//$res1 = Db::name('goods_configure')->where(array('goods_id'=>array('eq',$goodsid)))->update($arr);
		return $res;
		//}
		
		}


	 public static function find($id){
	 	$res = Db::name('product')->find($id);
	 	return $res;
	 } 

	 public static function up(array $data){
	 	$res = Db::name('product')->update($data);
	 	return $res;
	 }


	

}